<template>
	<view class="settlement-page-box">

		<scroll-view class="settlement-scroll-box" scroll-y>
			<view class="settlement-scroll-content">
				<view class="settlement-list-box">
					<view class="settlement-list">
						<view class="settlement-list-time flex">
							<view>营业时间:</view>
							<view style="margin-left: 10rpx;display: flex;font-size: 28rpx;flex: 1;justify-content: flex-end;">
								<view v-for="(item,index) in business_time" :key="index">{{item[0]}}-{{item[1]}};
								</view>
							</view>
						</view>
					</view>
					<view class="settlement-list" v-if="pickup_type==2">
						<!-- <text class="settlement-list-time">配送时间: {{send_time}}</text> -->
						<view class="settlement-list-time flex">
							<view>配送时间:</view>
							<view style="margin-left: 10rpx;display: flex;font-size: 28rpx;flex: 1;justify-content: flex-end;">
								<view v-for="(item,index) in send_time" :key="index">{{item[0]}}-{{item[1]}}; </view>
							</view>
						</view>
					</view>
					<view class="settlement-list">
						<view class="settlement-list-title">
							<text>配送方式</text>
						</view>
						<view class="settlement-list-content">
							<view class="settlement-list-content-column">
								<block v-for="(item,index) in pickup_list" :key="item.id">
									<view class="settlement-list-choose" @tap="sendMethod" :data-index="item.id">
										<text :style="'color:' + (pickup_type==item.id?'#000':'#999')">{{item.id==1?('到店'+item.name):item.name}}</text>
										<image :src="pickup_type==item.id?'/static/images/choose-circle-1.png':'/static/images/choose-circle-2.png'">
										</image>
									</view>
								</block>
							</view>
						</view>
					</view>
					<view class="settlement-list" v-if="pickup_type==1||pickup_type==2">
						<view class="settlement-list-title">
							<text>时间选择</text>
						</view>
						<view class="settlement-list-choose">
							<!-- #ifndef MP-ALIPAY -->
							<picker class="settlement-time-picker timer-picker-color" mode="multiSelector" @change="bindStartMultiPickerChange" @tap="pickerTap"
								@columnchange="bindMultiPickerColumnChange" :value="multiIndex" :range="multiArray">
								{{startDate==''?('点击选择'+(pickup_type==2?'起送':'自提')+'时间'):startDate}}
							</picker>
							<!-- #endif -->
							<!-- #ifdef MP-ALIPAY -->
							<uni-popup type="bottom" ref="popup" ::mask-click="false" :is-mask-click="false" style="background: rgba(255,255,255,1);"
								class="popup">
								<view class="operate">
									<view @click="successSelect" class="sure">完成</view>
								</view>
								<picker-view indicator-style="{height: 100rpx}" class="settlement-time-picker timer-picker-color" :value="multiIndex"
									@click="pickerTap" @change="bindStartMultiPickerChange" style="background: rgba(255,255,255,1);">
									<picker-view-column v-for="(col,index) in  multiArray" :key="index">
										<view class="item" v-for="(item,i) in col" :key="i">{{item}}</view>
									</picker-view-column>
								</picker-view>
							</uni-popup>
							<view class="select-time" @click="showSelectTime">
								{{startDate==''?('点击选择'+(pickup_type==2?'起送':'自提')+'时间'):startDate}}
							</view>
							<!-- #endif -->
							<image class="settlement-list-choose-right" src="/static/images/arrow-right-1.png"></image>
						</view>
					</view>

				</view>

				<!-- 祝福语功能 -->
				<view class="settlement-list-box" v-if="blessinfo.status==1" style="padding:0">
					<view v-if="blessData.url" class="zhufu_bg_now">
						<view class="blesstitle">
							<text class="blessttext">{{blessData.type==1?'视频':'录音'}}</text>
							<text class="blessttext" style="color:#ccc" v-if="blessData.length">时长:{{blessData.length + 's'}}</text>
						</view>
						<view class="play_icon">
							<image class="play_pic" v-if="isPlaying" @click="toStop" src="../../../static/images/audio_play_end.png"></image>
							<image class="play_pic" @click="toPlay(blessData.type)" v-else src="../../../static/images/audio_play_start.png"></image>
							<view>
								<uni-icons @click="toEdit(blessData.type)" type="gear-filled" size="16" color="#ccc">
								</uni-icons>修改
								<uni-icons @click="deleteItem(blessData.type)" style="margin-left:20rpx" type="trash-filled" size="16" color="#ccc"></uni-icons>
								删除
							</view>
						</view>
					</view>
					<view class="zhufu_bg" v-else @click="toBlessing">
						<image style="width:100%;height:100%" :src="blessinfo.entrance_style"></image>
						<!-- <image style="width:100%;height:100%" src="https://lscs.mobxcx.com/Public/images/blessing_default.png"></image> -->
					</view>
				</view>

				<view class="settlement-list-box">
					<!-- 引入模板 -->
					<block v-if="pickup_type==2||pickup_type==3">
						<view class="settlement-list" v-if="isShowAddress">
							<address-diy :address="address"></address-diy>
						</view>
						<view class="settlement-list">
							<block v-if="pickup_type==2">
								<view class="settlement-distance">范围: {{math/1000}}km</view>
								<view class="settlement-distance">距离: {{distance}}km</view>
							</block>
							<view v-else class="settlement-distance"></view>
							<view class="settlement-list-price-box" v-if="isShowFee == 1">
								<text class="settlement-list-small-text">配送费:</text>
								<text class="settlement-list-price">￥{{delivery_fee}}</text>
							</view>
							<view class="settlement-list-price-box" style='text-decoration: line-through;' v-if="isShowFee == 2">
								<text class="settlement-list-small-text">配送费:</text>
								<text class="settlement-list-price">￥{{delivery_fee}}</text>
							</view>
						</view>
						<view v-if="delivery_status == 1">
							<express-fee :delivery_cost="delivery_cost"></express-fee>
						</view>
					</block>
					<block v-if="pickup_type==1">
						<view class="settlement-list flexStart">
							<text>姓名</text>
							<input type="text" :value="name" @input="nameFun" placeholder-class="pl" placeholder="联系人姓名"></input>
						</view>
						<view class="settlement-list flexStart">
							<text>手机号</text>
							<input type="number" maxlength="11" :value="call" @input="callFun" placeholder-class="pl" placeholder="联系人手机号"></input>
						</view>
					</block>
				</view>

				<view class="settlement-list-box">
					<view class="settlement-list" v-if="vip && userInfo.platform_type == 1">
						<view class="settlement-vip-box">
							<view class="settlement-vip">
								<text>会员卡：{{vip.card_num}}</text>
							</view>
							<view class="settlement-vip">
								<text>余额：{{vip.balance}}</text>
								<text>{{integral_name}}：{{vip.integral}}</text>
							</view>
						</view>
					</view>
					<view class="settlement-list flexStart">
						<view class="settlement-goods-img">
							<image mode="aspectFit" :src="goods_image"></image>
						</view>
						<view class="settlement-goods-con">
							<view class="settlement-goods-name">{{goods_name}}</view>
							<view class="settlement-goods-sku" v-if="sku">{{sku}}</view>
							<view class="settlement-goods-num">
								<text>x</text>
								<text>{{alertNum}}</text>
							</view>
						</view>
						<view class="settlement-goods-price">
							<text>￥{{goods_price}}</text>
						</view>
					</view>
				</view>

				<view class="settlement-list-box">
					<view class="settlement-list">
						<text>给卖家留言</text>
						<text class="remark-more">最多100字</text>
					</view>
					<textarea maxlength="100" placeholder="留言" v-model="message" class="textarea-t" :always-embed="true" placeholder-class="textarea-p"
						cursor-spacing="0"></textarea>
				</view>
			</view>
		</scroll-view>
		<!-- 底部 -->
		<view class="settlement-footer">
			<view class="settlement-footer-left">
				<view class="settlement-footer-left-all">
					<text>合计:</text>
					<text>￥{{allMoney}}</text>
				</view>
			</view>
			<view @click="payBtn">
				<view class="settlement-pay-btn" v-if="canClick">提交订单</view>
				<view class="settlement-pay-btn settlement-pay-btn-dis" v-else>提交订单</view>
			</view>
		</view>

		<view class="livePlay" v-if="videoShow">
			<view class="closeIcon">
				<uni-icons style="margin-right:30rpx" type="close" size="18" @click="closeVedio"></uni-icons>
				<!-- <uni-icons type="download" size="18" @click="uploadVedio"></uni-icons> -->
			</view>
			<video id="myVideo" style="width: 100%;height: 95%;" :src="blessData.url" controls enable-play-gesture></video>
		</view>
	</view>
</template>

<script>
	// pages/Seckill_paymentOrder/Seckill_paymentOrder.js
	var app = getApp().globalData;
	const innerAudioContext = uni.createInnerAudioContext();
	const videoContext = uni.createVideoContext('myVideo')
	const recorderManager = uni.getRecorderManager();
	import addressDiy from '@/components/address-diy.vue'
	import expressFee from '@/components/express-fee.vue'
	
	export default {
		data() {
			return {
				startDate: "",
				choose_send_time: '',
				//选择的配送时间
				choose_pick_time: '',
				//选择的自提时间
				multiArray: [
					['今天', '明天', '3-2', '3-3', '3-4', '3-5'],
					[0, 1, 2, 3, 4, 5, 6],
					[0, 10, 20]
				],
				//时间选择器里面的值
				multiIndex: [0, 0, 0],
				//被选中的时间下标
				payOrder: [],
				orderAll: 0,
				//总价
				message: '',
				sku: '',
				appearPay: false,
				pickup_type: 0,

				//1自提 2配送 3快递发货
				canClick: false,
				delivery_fee: 0,
				showTextarea: false,
				textFocus: false,
				textPadding: 0,
				name: '',
				call: null,
				business_state: 1,
				self_pick: 1,
				//是否开启到店自提  0开启  1关闭
				delivery: 1 //是否开启配送  0开启  1关闭,
					,
				showpaypassword: false,
				password: "",
				isFocus: false,
				payIndex: "",
				id: "",
				alertNum: "",
				address: {},
				allMoney: "",
				distance: "",

				goods_image: '',
				goods_name: '',
				goods_price: '',
				send_time: '',
				business_time: '',
				cacul_time: [],
				needmoney: '',
				math: '',
				vip: '',
				delivery_set: '',
				isShowAddress: false,
				delivery_status: 0,
				delivery_cost: '',
				isShowFee: 1,
				entry_num_privacy: 0,
				videoShow: false,
				blessinfo: {
					status: '0', // 权限
					entrance_style: '',
					privacy_statement: '',
				}, // 祝福语info
				blessData: {
					saveName: '',
					type: '',
					url: '',
					length: 0,
					storage_type: '',
				},
				isPlaying: false,
				imageValue: '', // 祝福语image
				pickup_list: [],
				send_delayed_time: null,
				pickup_delayed_time: null,
				auto_set_time: 1,
				isShowDialog: false,
				userInfo: {},
				integral_name:''
			};
		},

		components: {
			addressDiy,
			expressFee
		},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			uni.removeStorageSync('shoppingAddress');
			uni.removeStorageSync('blessData')
			const userInfo = uni.getStorageSync('userInfo')
			this.setData({
				id: options.spike_id,
				alertNum: options.buy_number,
				userInfo: userInfo ? userInfo : {}
			});
			this.getBuyData();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.integral_name = this.$store.integral_name;
			var address = uni.getStorageSync('shoppingAddress');
			let params = uni.getStorageSync('blessData')
			if (params) {
				params = JSON.parse(params)
				this.$set(this.blessData, 'saveName', params.url);
				this.$set(this.blessData, 'storage_type', params.storageType);
				this.$set(this.blessData, 'type', params.type);
				this.$set(this.blessData, 'url', params.address);
				this.$set(this.blessData, 'length', params.audio_length);
			}
			this.setData({
				isShowAddress: true,
				blessData: this.blessData
			})
			if (address) {
				this.setData({
					address: address
				});
			}

			var that = this;
			getApp().globalData.sendRequest({
				url: '/Pay/getUserDetail',
				type: "post",
				showLoading: false,
				data: {},
				success: function(res) {
					if (res.status == 1) {
						var obj = {
							vip: res.vip_data
						};
					} else {
						var obj = {
							vip: null
						};
					}

					that.setData(obj);
				}
			});
			if (Object.keys(this.address).length != 0 && (this.pickup_type == 2 || this.pickup_type == 3)) {
				this.range(function() {
					that.reAllMoney();
				});
			} else {
				that.reAllMoney();
			}
		},
		onHide() {
			this.setData({
				isShowAddress: false
			})
		},
		onUnload: function() {},
		methods: {
			//点击时间选择器
			pickerTap: function() {
				this.setData({
					cacul_time: this.pickup_type == 2 ? app.handleTimeArr(this.send_time) : app.handleTimeArr(
						this.business_time)
				})
				this.loadMonthDate();
				this.loadHours();
				this.loadMinutes();
			},
			//选择配送方式
			sendMethod: function(e) {
				var index = e.currentTarget.dataset.index;
				console.log(index)
				this.setData({
					pickup_type: parseInt(index),
					startDate: index == 2 ? this.choose_send_time : this.choose_pick_time,
				});

				if (index == 1) {
					this.setData({
						canClick: true
					});
				}

				if (index == 2 || index == 3) {

					if (Object.keys(this.address).length != 0) {
						this.range(() => {
							this.reAllMoney();
						});
					} else {
						this.setData({
							canClick: false
						});
					}
				} else {
					this.reAllMoney();
				}

				// 重新选择时间
				this.auto_set_time == 1 && this.selectTime()
			},


			//修改时间选择器的列
			bindMultiPickerColumnChange: function(e) {
				var multiIndex = this.multiIndex; // 把选择的对应值赋值给 multiIndex=[0,0,0]
				multiIndex[e.detail.column] = e.detail.value; // 然后再判断当前改变的是哪一列,如果是第1列改变
				if (e.detail.column === 0) {
					//日期列改变
					multiIndex[1] = 0;
					multiIndex[2] = 0;
					this.setData({
						multiIndex: multiIndex
					});
					this.loadHours();
					this.loadMinutes()
				} else if (e.detail.column === 1) {
					// 如果是第2列 小时改变
					multiIndex[2] = 0;
					this.setData({
						multiIndex: multiIndex
					});
					this.loadMinutes()
				}
			},
			//确认修改时间
			bindStartMultiPickerChange: function(e) {
				// console.log('最终确认配送的时间')
				var monthDay = this.multiArray[0][e.detail.value[0]];
				var hours = this.multiArray[1][e.detail.value[1]];
				var minute = this.multiArray[2][e.detail.value[2]];
				// console.log('monthDay=', monthDay, 'hours', hours, 'minute', minute)
				if (monthDay === "今天") {
					var month = new Date().getMonth() + 1;
					var day = new Date().getDate();
					monthDay = month + "月" + day + "日";
				} else if (monthDay === "明天") {
					var date1 = new Date();
					date1.setDate(new Date().getDate() + 1);
					monthDay = date1.getMonth() + 1 + "月" + date1.getDate() + "日";
				} else {
					var month = monthDay.split("-")[0]; // 返回月

					var day = monthDay.split("-")[1]; // 返回日

					monthDay = month + "月" + day + "日";
				}

				var startDate = monthDay + " " + hours + ":" + minute;
				var obj = {
					startDate: startDate,
					multiIndex: e.detail.value
				};

				if (this.pickup_type == 2) {
					//配送
					obj.choose_send_time = startDate;
				} else {
					//自提
					obj.choose_pick_time = startDate;
				}
				this.setData(obj);
			},
			//生成可选月日
			loadMonthDate() {
				var multiArray = this.multiArray;
				const delay_time = this.pickup_type == 2 ? (this.send_delayed_time * 60) : (this.pickup_delayed_time * 60)
				multiArray[0] = app.createMonthDay(this.cacul_time, delay_time);
				this.setData({
					multiArray: multiArray
				});
				this.$forceUpdate()
			},
			//生成可选时
			loadHours() {
				var multiArray = this.multiArray;
				const delay_time = this.pickup_type == 2 ? (this.send_delayed_time * 60) : (this.pickup_delayed_time * 60)
				multiArray[1] = app.createHours(this.cacul_time, this.multiArray, this.multiIndex, delay_time);
				this.setData({
					multiArray: multiArray
				});
				this.$forceUpdate()
			},
			//生成可选分
			loadMinutes() {
				var multiArray = this.multiArray;
				const delay_time = this.pickup_type == 2 ? (this.send_delayed_time * 60) : (this.pickup_delayed_time * 60)
				multiArray[2] = app.createMinutes(this.cacul_time, multiArray, this.multiIndex, delay_time);
				this.setData({
					multiArray: multiArray
				});
				this.$forceUpdate()
			},
			//点击留言
			showRemark: function() {
				var that = this;
				this.setData({
					textFocus: true,
					showTextarea: true
				});
			},

			//买家留言
			messageFun(e) {
				this.setData({
					message: e.detail.value
				});
			},

			textBlur: function() {
				this.setData({
					textFocus: false,
					showTextarea: false
				});
			},

			//取消会员密码
			cancelpassword: function() {
				this.setData({
					showpaypassword: false,
					password: '',
					canClick: true
				});
			},

			// 弹出框（会员卡支付密码）
			set_Focus() {
				this.setData({
					isFocus: true
				});
			},

			//输入支付密码
			set_password: function(e) {
				var password = e.detail.value;

				if (password.length >= 6) {
					this.setData({
						password: password,
						isFocus: false
					});
					this.vipPay();
				} else {
					this.setData({
						password: password
					});
				}
			},
			inputMoneyBlur: function() {
				this.setData({
					isFocus: false
				});
			},

			distributionChoose(e) {
				var index = e.currentTarget.dataset.index;
				this.setData({
					pickup_type: index,
					startDate: index == 1 ? this.choose_pick_time : this.choose_send_time
				});

				if (index == 2 || index == 3) {
					if (Object.keys(this.address).length != 0) {
						this.range(() => {
							this.reAllMoney();
						});
					} else {
						this.setData({
							canClick: false
						});
					}
				} else {
					this.reAllMoney();
				}
			},

			// 配送方式选择
			chooseType() {
				this.setData({
					appearPay: true
				});
			},

			// 提货人姓名
			nameFun(e) {
				this.setData({
					name: e.detail.value
				});
			},

			// 提货人联系方式
			callFun(e) {
				let telReg = /^1[3456789]\d{9}$/
				if (!telReg.test(e.detail.value)) {
					this.canClick = false
				} else {
					this.setData({
						call: e.detail.value,
						canClick: true
					});
				}

			},

			choosePayText(e) {
				var index = e.currentTarget.dataset.index;
				this.setData({
					payIndex: index
				});
			},


			// 编辑
			toEdit(type) {
				type == 2 ? this.toStop() : this.closeVedio()
				let blessData = uni.getStorageSync('blessData')
				if (blessData) {
					blessData = Object.assign(JSON.parse(blessData), {
						flag: 'isEdit'
					})
				}
				uni.navigateTo({
					url: '../../order/selectBlessingWays/selectBlessingWays?blessData=' + JSON.stringify(blessData)
				})
			},

			// 关闭视频
			closeVedio() {
				videoContext.stop()
				this.isPlaying = false
				this.videoShow = false
			},


			// 获取数据
			getBuyData() {
				uni.showLoading({
					title: '加载中',
					// #ifndef MP-ALIPAY
					mask: true,
					// #endif
				});
				var that = this;
				getApp().globalData.sendRequest({
					url: '/Spike/getBuyData_v1',
					type: "post",
					data: {
						spike_id: this.id,
						buy_number: this.alertNum
					},
					success: async (res) => {
						uni.hideLoading();

						if (res.status == 1) {
							if (res.data.storeSet.blessing_status) {
								// 获取祝福语权限
								that.getBlessPower()
							}
							let pickup_type = 0;
							that.canClick = true;
							var obj = {
								delivery_set: res.data.delivery_set
							};
							let address = that.address.id ? that.address : (res.data.address ? res.data.address : {});
							uni.setStorageSync('shoppingAddress', Object.keys(address).length != 0 ? address : '')
							that.setData({
								goods_image: res.data.buy_data.image,
								goods_name: res.data.buy_data.goods_name,
								sku: res.data.buy_data.sku_name ? res.data.buy_data.sku_name : '',
								goods_price: res.data.buy_data.spike_price,
								orderAll: res.data.buy_data.all_money,
								allMoney: res.data.buy_data.all_money,
								send_time: res.data.storeSet.new_business,
								business_time: res.data.storeSet.new_business_time,
								needmoney: res.data.storeSet.starting_price,
								math: res.data.storeSet.service_radius,
								business_state: res.data.storeSet.business_non_order,
								address: address,
								name: that.name ? that.name : res.data.link_name,
								call: that.call ? that.call : res.data.mobile_phone,
								vip: res.data.vip_info,
								delivery_set: res.data.delivery_set,
								pickup_type: pickup_type,
								delivery_status: res.delivery_status,
								delivery_cost: res.delivery_cost,
								send_delayed_time: res.data.storeSet.send_delayed_time,
								pickup_delayed_time: res.data.storeSet.pickup_delayed_time,
								auto_set_time: res.data.storeSet.auto_set_time
							});

							that.auto_set_time == 1 && await that.selectTime()
							let result = await that.sendPowerLevel(res.data.delivery_set)
							that.pickup_type = pickup_type = result
							if ((pickup_type == 2 || pickup_type == 3) && Object.keys(address).length == 0) {
								that.canClick = false
							}
							if ((pickup_type == 2 || pickup_type == 3) && Object.keys(this.address).length != 0) {
								that.range(function() {
									that.reAllMoney();
								});
							} else {
								that.reAllMoney()
							}
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 1500
							});
						}
					}
				});
			},

			// 修改选择时间
			selectTime() {
				let date_params = {
					detail: {
						value: [0, 0, 0]
					}
				}
				this.pickerTap()
				this.bindStartMultiPickerChange(
					date_params
				)
			},

			// 获取祝福语权限
			async getBlessPower() {

				try {
					const {
						data,
						status
					} = await this.$request('Blessing/Applets/privacyStatement')
					if (status == 1) {
						this.blessinfo = Object.assign({}, data)
					} else {
						uni.showToast({
							title: '获取祝福语权限失败',
							icon: 'none'
						})
					}
				} catch (err) {
					console.log(err)
				}
			},


			// 配送等级权限
			sendPowerLevel(delivery_set) {
				const that = this
				let pickup_type = 0
				return new Promise((resolve) => {
					app.sendRequest({
						url: '/MerInterface/storeConfigInfo',
						success: function({
							status,
							message,
							data
						}) {
							console.log(data)
							if (status == 1) {
								if (!data || !data.distribution_json) {
									that.pickup_list = [{
											name: '快递配送',
											id: 3
										},
										{
											name: '同城配送',
											id: 2
										},
										{
											name: '自提',
											id: 1
										},
									]

								} else {
									that.pickup_list = JSON.parse(data.distribution_json)
								}
								that.pickup_list = that.pickup_list.filter(x => {
									return (delivery_set[x.id - 1] > 0)
								})
								pickup_type = that.pickup_list[0].id
								resolve(pickup_type)
							} else {
								uni.showToast({
									title: message,
									icon: 'none'
								})
							}
						}
					})

				})

			},


			// 上传祝福语
			toBlessing() {
				if (this.entry_num_privacy == 0) {
					this.entry_num_privacy++
					uni.navigateTo({
						url: '..../order/privacyStatement/privacyStatement?info=' + this.blessinfo
							.privacy_statement
					})
				} else {
					uni.navigateTo({
						url: '../../order/selectBlessingWays/selectBlessingWays'
					})
				}

			},




			// 删除
			deleteItem(type) {
				type == 1 ? this.closeVedio() : this.toStop()
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要删除祝福吗?',
					success: async (res) => {
						if (res.confirm) {
							let obj = {
								storage_type: that.blessData.storage_type,
								url: that.blessData.saveName
							}
							try {
								const res = await this.$request('Blessing/Applets/deleteBlessing', obj)
								if (res.status == 1) {
									uni.showToast({
										title: '删除成功',
									})
									that.videoShow = false
									that.blessData = {}
								}
								uni.removeStorageSync('blessData')
							} catch (err) {
								console.log(err)
							}
						}
					}
				})

			},

			// 播放
			toPlay(type) {
				let _this = this
				// 视频
				if (type == 1) {
					this.videoShow = true
					videoContext.play()
				} else {
					console.log(type, 11)
					// 录音
					_this.isPlaying = true

					innerAudioContext.src = _this.blessData.url;
					console.log(innerAudioContext.src)
					innerAudioContext.play()
					innerAudioContext.onPlay(() => {
						innerAudioContext.onTimeUpdate(() => {
							console.log(innerAudioContext.duration);
							_this.blessData.length = innerAudioContext.duration
						})
						setTimeout(() => {
							console.log(innerAudioContext.duration)
							_this.blessData.length = innerAudioContext.duration
						}, 1000)
					})
					innerAudioContext.onEnded(() => {
						_this.isPlaying = false
					})
				}
			},

			// 播放暂停
			toStop() {
				innerAudioContext.pause()
				this.isPlaying = false
			},

			reAllMoney() {
				var pickup_type = this.pickup_type;
				var all_money = parseFloat(this.orderAll);
				let canClick = true
				if (pickup_type == 2 || pickup_type == 3) {
					if (Object.keys(this.address).length == 0) {
						canClick = false
					}
					var delivery_fee = this.delivery_fee;
					if (this.delivery_status == 1 && (all_money >= parseFloat(this.delivery_cost))) {
						delivery_fee = 0
						this.isShowFee = 2;
					} else {
						this.isShowFee = 1;
					}
					all_money = (all_money * 100 + delivery_fee * 100) / 100;
				}
				this.setData({
					allMoney: all_money.toFixed(2),
					canClick: canClick
				});
			},

			range: function(fn) {
				var that = this;
				if (!this.address.id) {
					typeof fn == "function" && fn();
					return;
				}
				getApp().globalData.sendRequest({
					url: '/Address/range_v2',
					type: "post",
					data: {
						address_id: that.address.id,
						order_genre: 3,
						//秒杀
						spike_id: that.id,
						pickup_type: that.pickup_type,
						num: that.alertNum
					},
					success: function(res) {
						if (res.status == 1) {
							that.setData({
								delivery_fee: res.fee,
								distance: that.pickup_type == 2 ? res.distance : 0
							});

							if (typeof fn == "function") {
								fn();
							}
						} else {
							that.setData({
								canClick: false,
								delivery_fee: 0,
								distance: res.distance ? res.distance : 0
							});
							uni.showToast({
								title: res.msg ? ('地址: ' + res.msg) : '收货地址不在配送范围内',
								icon: 'none',
								duration: 1500,
								mask: false
							});
						}
					}
				});
			},
			// 判断支付
			payBtn: function(e) {
				var business_state = this.business_state; //是否开启非营业时间下单
				var send_time = this.business_time;
				if (business_state == 2) {
					let start = send_time[0][0];
					let end = send_time[send_time.length - 1][1];
					let checktime = start + '-' + end;
					console.log('选取配送时间的开始时刻和结束时刻', checktime)
					if (!getApp().globalData.checkTime(checktime)) {
						uni.showModal({
							title: '提示',
							content: '当前时间不在今日营业时间范围内',
							showCancel: false
						});
						return;
					}
				} // 判断配送方式
				if (this.pickup_type == 1) {
					var dateTips = '请选择自提时间'; //自提

					var name = this.name;
					var call = this.call;
					var reg = /^1(3|4|5|6|7|8|9)\d{9}$/; // 验证名称

					if (!name || name.trim() == '') {
						uni.showToast({
							title: '请填写正确的姓名',
							icon: 'none',
							duration: 1500
						});
						return;
					} // 验证手机号


					if (!call || call.trim() == '' || !reg.test(call)) {
						uni.showToast({
							title: '请填写正确的手机号',
							icon: 'none',
							duration: 1500
						});
						return;
					}
				} else if (this.pickup_type == 2) {
					var dateTips = '请选择起送时间'; //配送

					var address = this.address;

					if (Object.keys(this.address).length == 0) {
						uni.showToast({
							title: '请选择收货地址',
							image: "/static/images/tip.png",
							duration: 800,
							mask: true
						});
						return false;
					}
				} else if (this.pickup_type != 3) {
					uni.showToast({
						title: '请选择配送方式',
						icon: 'none',
						duration: 1000,
						mask: false
					});
					return;
				}

				var startDate = this.startDate;

				if ((startDate == "" || startDate == 'undefined') && this.pickup_type != 3) {
					uni.showToast({
						title: dateTips,
						icon: 'none',
						duration: 1000,
						mask: false
					});
					return;
				}

				this.placeOrder();
			},

			// 下单
			placeOrder() {
				var that = this;
				uni.showLoading({
					title: '下单中...',
					mask: true
				});
				var thisYears = new Date().getFullYear();
				var startDate = this.startDate; //时间

				if (that.pickup_type == 3) {
					startDate = '';
				} else {
					startDate = startDate.replace("月", "-");
					startDate = startDate.replace("日", " ");
					startDate = thisYears + "-" + startDate + ":00";
				}

				getApp().globalData.sendRequest({
					url: '/Spike/placeOrder_v3',
					type: "post",
					data: {
						spike_id: that.id,
						buy_number: that.alertNum,
						pickup_type: that.pickup_type,
						delivery_fee: that.delivery_fee ? that.delivery_fee : 0,
						address_id: that.address ? that.address.id : 0,
						user_name: that.name,
						user_phone: that.call,
						remark: that.message,
						start_date: startDate
					},

					success(res) {
						uni.hideLoading();

						if (res.status == 1) {
							uni.redirectTo({
								url: '/pages/order/waitPay/waitPay?order_no=' + res.data.order_no
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 1200
							});
						}
					}

				});
			},


			// 完成时间筛选框
			successSelect() {
				this.$refs.popup.close()
			},

			// 支付宝小程序选择时间
			showSelectTime() {
				this.$refs.popup.open('bottom')
			},
		}
	};
</script>
<style>
	@import "./Seckill_paymentOrder.css";

	.flex {
		width: 100%;
		display: flex;
		justify-content: space-between;

	}

	.lineH {
		/* line-height: 48rpx; */
	}

	.zhufu_bg {
		width: 100%;
		height: 200rpx;
	}

	.zhufu_bg_now {
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 0 30rpx;
	}



	.play_pic {
		width: 40rpx;
		height: 40rpx;
		display: inline-block;
		margin-right: 20rpx;
	}

	.play_icon {
		display: flex;
		align-items: center;

	}

	.blesstitle {
		display: flex;
		flex-direction: column;

	}

	.blessttext {
		font-size: 24rpx;
		color: #333;
	}

	.livePlay {
		position: absolute;
		top: 50%;
		left: 50%;
		width: 600rpx;
		height: 600rpx;
		transform: translate(-50%, -50%);
		z-index: 99;
		display: flex;
		flex-direction: column;

	}

	.closeIcon {
		flex: 1;
		magrin-bottom: 10rpx;
		display: flex;
		justify-content: flex-end;
	}
</style>
<style lang="less" scoped>
	.settlement-list-choose {
		.select-time {
			color: #ff3d3d;
		}

		/deep/.uni-popup {
			background-color: #fff;

			.uni-transition {
				background-color: #fff;

				.uni-popup__wrapper-box {
					background-color: #fff;

					.operate {
						display: flex;
						justify-content: flex-end;
						align-items: center;
						padding: 10px 20px 0 20px;
						position: absolute;
						z-index: 9999;
						width: 100%;
						box-sizing: border-box;

						.sure {
							color: #07c160;
						}
					}
				}
			}
		}
	}
</style>
